#include "head.h"

#define FIFO_NAME "./fifo_test"

int main(int argc, char const *argv[])
{
    mkfifo( FIFO_NAME, 0664 );

    int FifoFd;
    FifoFd = open( FIFO_NAME, O_RDONLY );
    if ( -1 == FifoFd )
    {
        perror( "fail open fifo" );
        return -1;
    }

    int i;
    for( i = 1; i <= 100; ++i)
    {
        char strBuff[1024] = {0};
        ssize_t Ret;
        Ret = read( 0, strBuff, sizeof(strBuff) );
        if ( -1 == Ret )
        {
            perror( "fail read stdin" );
            return -1;
        }
        printf( "Counter %3d --- Recvfrom stdin: %s\n", i, strBuff );

        memset( strBuff, 0, sizeof(strBuff) );
        Ret = read( FifoFd, strBuff, sizeof(strBuff) );
        if ( -1 == Ret )
        {
            perror( "fail read fifo" );
            return -1;
        }
        printf( "Counter %3d --- Recvfrom FIFO : %s\n", i, strBuff );

    }

    close( FifoFd );

    return 0;
}
